<template>
  <div class="recommend">
    <h3 class="title">
      精品推荐
    </h3>
    <div class="items">
      <div class="item"
        @click="clickItem(item.id)"
        v-for="item in items" :key="item.id">
        <img v-lazy="item.pic" class="item-img">
        <div class="item-info">
          <h4>{{item.name}}</h4>
          <div class="item-desc">
            {{item.characteristic? item.characteristic.length < 10 ?item.characteristic.length:item.characteristic.substr(0, 10)+'...' : '暂无描述'}}
          </div>
          <div class="item-action">
            <div class="price">
              ￥{{item.minPrice}}
            </div>
            <van-icon
              @click.stop="clickAddCart(item.id, item)"
              name="gouwuche" class-prefix="icon" size="24" color="#ff734c"></van-icon>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    items: {
      type: Array,
      required: true
    }
  },
  methods: {
    clickAddCart (id, item) {
      // 点击加入购物车图标
      this.$emit('clickAddIcon', { id, item })
    },
    clickItem (id) {
      // 点击商品
      this.$emit('clickItem', id)
    }
  }
}
</script>

<style lang="scss" scoped>
.recommend{
  padding:0 10px;
  .title{
    margin: 0;
    line-height: 1.25rem;
    font-size: 18px;
    text-align: center;
    color: #333;
  }
  .item{
    display: flex;
    background-color: #fff;
    margin-bottom: 10px;
    border-radius: 5px;
    overflow: hidden;
    font-size: 14px;
    .item-img{
      width: 3.75rem;
      height: 3.75rem;
    }
    .item-info{
      flex: 1;
      padding-left: 10px;
      h4{
        margin: 0;
        font-size: 16px;
        color: #333;
        line-height: 30px;
      }
      .item-desc{
        font-size: 14px;
        color: #666;
        margin:5px 0;
      }
      .item-action {
        display: flex;
        justify-content: space-between;
        height: 1rem;
        padding-right: 10px;
        align-items: center;
        .price{
          font-size: 16px;
          font-weight: 900;
          color: #333;
        }
      }
    }
  }
}
</style>
